package com.kwan.xframe.common.adatper;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;
import androidx.lifecycle.Lifecycle;
import androidx.viewpager2.adapter.FragmentStateAdapter;

/**
 *
 * @author Mr.Kwan
 * @date 2016-5-4
 */
public class CommonFragmentPageAdapter extends FragmentStateAdapter {

	/**
	 * fragment列表
	 */

	private List<Fragment> mFragments = new ArrayList<>();
	/**
	 * tab名的列表
	 */

	private List<String> mTitles = new ArrayList<>();

	public CommonFragmentPageAdapter(@NonNull FragmentActivity fragmentActivity, List<Fragment> fragments ,List<String> titles) {
		super(fragmentActivity);
		mFragments = fragments;
		mTitles = titles;
	}

	public CommonFragmentPageAdapter(@NonNull Fragment fragment) {
		super(fragment);
	}

	public CommonFragmentPageAdapter(@NonNull FragmentManager fragmentManager, @NonNull Lifecycle lifecycle) {
		super(fragmentManager, lifecycle);
	}

	public void addFragment(Fragment fragment, String title) {
		mFragments.add(fragment);
		mTitles.add(title);
	}

	public List<String> getTitles() {
		return mTitles;
	}

	@NonNull
	@Override
	public Fragment createFragment(int position) {
		return mFragments.get(position);
	}

	@Override
	public int getItemCount() {
		return mFragments.size();
	}
}
